package servlet;


import com.google.gson.Gson;
import dao.DB;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;


//同意添加好友
@WebServlet("/agreeaddFri")
public class agreeaddFri extends HttpServlet {

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("UTF-8");
        resp.setCharacterEncoding("UTF-8");
        String uid = req.getParameter("uid");
        String fid = req.getParameter("fid");

        int tmp1 = DB.executeUpdate("INSERT INTO `friend`( `userid`, `friendid`,  `friStatus`) " +
                "VALUES ( "+uid+", "+fid+",  "+true+");");
        int tmp2=  DB.executeUpdate("UPDATE `friend` SET `friStatus` = ? WHERE userid = ? and friendid=?;",true,fid,uid);

        resp.getWriter().print(new Gson().toJson(tmp1));


    }
}
